unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, RzButton, frxClass, StdCtrls, frxDesgn;

type
  TForm1 = class(TForm)
    frxReport1: TfrxReport;
    RzBitBtn1: TRzBitBtn;
    frxUserDataSet1: TfrxUserDataSet;
    Btnx_1: TButton;
    frxDesigner1: TfrxDesigner;
    procedure RzBitBtn1Click(Sender: TObject);
    procedure frxUserDataSet1GetValue(const VarName: String;
      var Value: Variant);
    procedure Btnx_1Click(Sender: TObject);
  private
    FStrsData:TStringList; //Strs of TDemoData;
  public
    procedure PrepareData;
  end;

  TDemoData=class(TObject)
  public
    Field1:Integer;
    Field2:string;
    Field3:string;
    Field4:string;
    Field5:string;
  end;

  

var
  Form1: TForm1;

implementation

uses
  Class_KzPrint;

{$R *.dfm}

procedure TForm1.PrepareData;
var
  I:Integer;
  DemoDataA:TDemoData;
begin

  if FStrsData<>nil then
  begin
    FreeAndNil(FStrsData);
  end;
  FStrsData:=TStringList.Create;
  
  for I:=0 to 30 do
  begin
    DemoDataA:=TDemoData.Create;
    with DemoDataA do
    begin
      Field1:=I+1;
      Field2:='Field2';
      Field3:='Field3';
      Field4:='Field4';
      Field5:='Field5';
    end;

    FStrsData.AddObject('',DemoDataA);
  end;  
end;

procedure TForm1.RzBitBtn1Click(Sender: TObject);
begin
  PrepareData;

  frxUserDataSet1.RangeEnd:=reCount;
  frxUserDataSet1.RangeEndCount:=FStrsData.Count;

  frxReport1.LoadFromFile('1.fr3');
  frxReport1.ShowReport();
end;

procedure TForm1.frxUserDataSet1GetValue(const VarName: String;
  var Value: Variant);
var
  DemoDataA:TDemoData;
begin
  DemoDataA:=TDemoData(FStrsData.Objects[frxUserDataSet1.RecNo]);

  if VarName='Field1' then Value:=DemoDataA.Field1;
  if VarName='Field2' then Value:=DemoDataA.Field2;
  if VarName='Field3' then Value:=DemoDataA.Field3;
  if VarName='Field4' then Value:=DemoDataA.Field4;
  if VarName='Field5' then Value:=DemoDataA.Field5;
end;

procedure TForm1.Btnx_1Click(Sender: TObject);
begin
  PrepareData;

  frxUserDataSet1.RangeEnd:=reCount;
  frxUserDataSet1.RangeEndCount:=FStrsData.Count;

  frxReport1.LoadFromFile('1.fr3');
  frxReport1.DesignReport();
end;

end.
